package com.darker.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.darker.R;
import com.darker.domain.User;
import com.darker.service.IUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/users")
public class UserController {
    @Autowired
    IUserService userService;

    @GetMapping
    public R getAll() {
        return new R(true,userService.list());
    }

    @PostMapping
    public R save(@RequestBody User user) {
        return new R(userService.save(user));
    }

    @PutMapping()
    public R update(@RequestBody User user) {
        return new R(userService.updateById(user));
    }

    @DeleteMapping("{id}")
    public R delete(@PathVariable Integer id) {
        return new R( userService.removeById(id));
    }

    @GetMapping("{id}")
    public R getById(@PathVariable Integer id) {
        return new R(true,userService.getById(id));
    }

    @GetMapping("{page}/{size}")
    public R getPage(@PathVariable Integer page, @PathVariable Integer size) {
        return new R(true,userService.getPage(page, size));
    }

}
